<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>首页</h1>
<div>
    <div v-if="isLogin">
        <h3>欢迎{{user.nick}}回来</h3>
        <a href="/send.html">发布微博</a>
        <a href="/self.html">我的微博</a>
        <a href="javascript:void(0)" @click="loginOut()">退出登录</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册</a>
        <a href="/login.html">登录</a>
    </div>
    <hr>
    <div v-for="weibo in arr">
        <h3>
            <a :href="'/detail.html?id='+weibo.id">{{weibo.nick}}:{{weibo.content}}</a>
        </h3>
        <div>发布于:{{weibo.created}}</div>
        <img v-for="url in weibo.urlArr" :src="url" style="height: 100px;width: 100px" alt="">
    </div>


</div>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            isLogin:false,
            user:{},
            arr:[]
        },
        created:function (){
          axios.get("/currentUser").then(function (response){
              v.user=response.data;
              v.isLogin= response.data==""?false:true;
          });
            axios.get("/select").then(function (response){
                v.arr = response.data;
                for(let weibo of v.arr){
                    weibo.urlArr = weibo.urls==""?[]:weibo.urls.split(",");
                }
            })
        },


        methods:{
            loginOut(){
                if(confirm("您确认退出登录吗?")){
                    axios.get("/loginOut").then(function (response){
                        v.isLogin = false;
                    })
                }
            }
        }
    })
</script>
</body>
</html>